package com.realtyManage.springboot.Service.impl;

import com.realtyManage.springboot.Dao.CityRepository;
import com.realtyManage.springboot.Model.Do.City;
import com.realtyManage.springboot.Service.ICityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.List;

/**
 * IndexServiceImpl
 *
 * @Author 杭州素色网络科技有限公司
 * @Date 2019/3/22
 **/
@Service
@Transactional
public class CityServiceImpl implements ICityService{
    @Autowired
    private CityRepository cityRepository;

    @Override
    public List<Integer> getPCAIdByAreaId(Integer areaId) {
        ArrayList<Integer> list = new ArrayList<Integer>();
        City city = cityRepository.findById(areaId).orElse(null);
        while(city.getGrade() >= 3){
            list.add(city.getId());
            city = cityRepository.findById(city.getUpGradeId()).orElse(null);
        }
        return list;
    }
}
